package com.wsc.wisdomchina.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.wsc.wisdomchina.R;
import com.wsc.wisdomchina.javaBean.HomeModuleSubBean;

import java.util.List;

/**
 * 四大功能二级页面列表适配器
 * Created by ${wangtao} on 2017/2/25.
 */

public class HomeModuleSubAdapter extends BaseAdapter {

    private Context context;
    private List<HomeModuleSubBean> messageBeen;
    private LayoutInflater layoutInflater;

    public HomeModuleSubAdapter(Context context, List<HomeModuleSubBean> messageBeen) {
        this.context = context;
        this.messageBeen = messageBeen;
        this.layoutInflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return messageBeen.size();
    }

    @Override
    public Object getItem(int position) {
        return messageBeen.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = layoutInflater.inflate(R.layout.item_sdgn_second_list, null);
            convertView.setTag(new ViewHolder(convertView));
        }
        initializeViews((HomeModuleSubBean) getItem(position), (ViewHolder) convertView.getTag());
        return convertView;
    }

    private void initializeViews(final HomeModuleSubBean object, ViewHolder holder) {
        Glide.with(context).load(object.getIcon())
                .diskCacheStrategy(DiskCacheStrategy.ALL)
                .placeholder(R.mipmap.own_pic_logout)
                .into((ImageView)  holder.item_sdgn_second_list_icon);
        holder.item_sdgn_second_list_title.setText(object.getName());
        holder.item_sdgn_second_list_content.setText(object.getIntro());
    }

    public class ViewHolder {
        private ImageView item_sdgn_second_list_icon;//logo图片
        private TextView item_sdgn_second_list_title;//标题
        private TextView item_sdgn_second_list_content;//内容

        public ViewHolder(View view) {
            item_sdgn_second_list_icon = (ImageView) view.findViewById(R.id.item_sdgn_second_list_icon);
            item_sdgn_second_list_title = (TextView) view.findViewById(R.id.item_sdgn_second_list_title);
            item_sdgn_second_list_content = (TextView) view.findViewById(R.id.item_sdgn_second_list_content);
        }
    }
}
